<template>
	<view id="body">
		<!-- 订单信息导航栏 -->
		<view>
			<u-divider text="订单中心"></u-divider>
		    <u-tabs :list="classify" @click="fl()"></u-tabs>
		</view>
		<view id="order">
			<view class="order-card" v-for="(item,index) in orderList" :key="item.id" @click="ordeclick(index)">
				<view class="order-top">
					<text class="ordertitle">{{item.title}}</text>
					<text class="ordertype">{{ordertypeidtext}}</text>
					<text class="orderprice">{{item.price}}元</text>
					<view class="line">
						<u-line color="#7d7e80"></u-line>
					</view>
				</view>
				<view class="order-body">
					<view class="userimg">
						<u-avatar :src="item.issueUserImg" size="100rpx"></u-avatar>
					</view>
					<text class="ordername">{{item.issueUserName}}</text>
					<text class="ordercontent">{{item.content}}</text>
					<text class="date">发布时间:     {{item.createTime}}</text>
					<text class="orderbutton" @click.stop="orderbutton(index)" >立即接单</text>
				</view>
			</view>
		</view>
		<view class="loading" >
			<u-loadmore :status="status" :line="line" :nomoreText="nomoreText" /> 
		</view>
	</view>
</template>

<script>
	import {http} from "../static/service/requestAddress/rtas.js"
	export default {
		name:"indexGoodContent",
		data() {
			return {
				classify:[
						{
							name: '帮我买',
							url:http+"index/buyorder",
					    }, 
						{ 
					        name: '帮我送',
							url:http+"index/sendorder",
					    },
						{
					        name: '帮我做',
							url:http+"index/workorder",
					    }, 
						{
							name:"需求订单",
							url:http+"index/need",
						},
						],
				status:"loading",
				line:true,
				ordertypeidtext:"",//订单类型文本
				oldList:[],//接收的请求数据
				orderList:[],//渲染页面的数据 
				nomoreText:"没有更多了",
				}
	}, 	
	created(){
		//获取数据
		uni.request({
			url:this.classify[0].url, 
			method:"GET",
			complete:(res) =>{
				if(res.data.code == 20021){
					console.log("请求结果是"+res.data.date)
					this.oldList = res.data.date //将获取的数据存入旧数据的集合
					const datalist = res.data.date
					//对数据处理
					for(var i = 0; i < datalist.length;i++){
						if(datalist[i].createTime != ""){
							datalist[i].createTime = (datalist[i].createTime).substring(0,datalist[i].createTime.lastIndexOf(":"))
						}
					}
					this.orderList = datalist
					this.ordertypeidtext = "帮我买"
					this.status = "nomore"
				}else{
					uni.$u.toast("获取数据失败!")
				}
			}
		})
	},
	methods:{
			// 订单中心导航点击事件
			fl(itme){
				console.log(itme.index)
				this.orderList= []
				this.status="loading"
				//获取数据
				uni.request({
					url:this.classify[itme.index].url,
					method:"GET",
					complete:(res) =>{
						if(res.data.code == 20021){
							this.oldList = res.data.date //将获取的数据存入旧数据的集合
							const datalist = res.data.date
							//对数据处理
							for(var i = 0; i < datalist.length;i++){
								datalist[i].createTime = (datalist[i].createTime).substring(0,datalist[i].createTime.lastIndexOf(":"))
							}
							this.orderList = datalist
							this.status = "nomore"
							this.ordertypeidtext = this.classify[itme.index].name
						}else{
							uni.$u.toast("获取数据失败!")
						}
					}
				})
			},
			//订单点击事件
			ordeclick(index){
				uni.navigateTo({
					url:"/pages/massage/orderDetails?data="+ JSON.stringify(this.oldList[index])
				})
			},
			//接单按钮
			orderbutton(index){
				uni.navigateTo({
					url:"/pages/massage/orderDetails?data="+ JSON.stringify(this.oldList[index])
				})
			}
		}
	}
</script> 

<style scoped>
	@import url("../static/css/componentsCss/index/indexOrderCenter.css");
</style>